package main

import "fmt"

type ArithOperator struct {
	Metic string
	Next  *ArithOperator
}

func clumsy(N int) int {
	if N == 1 {
		return 1
	}
	var r int
	var mid []int
	head := &ArithOperator{
		Metic: "*",
	}
	tail := head
	tail.Next = &ArithOperator{
		Metic: "/",
	}
	tail = tail.Next
	tail.Next = &ArithOperator{
		Metic: "+",
	}
	tail = tail.Next
	tail.Next = &ArithOperator{
		Metic: "-",
	}
	tail = tail.Next
	tail.Next = head

	tail = head
	var tmp int = N
	for i := N - 1; i >= 0; i-- {
		if i == 0 {
			mid = append(mid, tmp)
			break
		}
		if tail.Metic == "*" {
			tmp = tmp * i
			tail = tail.Next
			continue
		}
		if tail.Metic == "/" {
			tmp = tmp / i
			tail = tail.Next
			continue
		}
		if tail.Metic == "+" {
			tmp = tmp + i
			tail = tail.Next
			continue
		}
		if tail.Metic == "-" {
			mid = append(mid, tmp)
			tmp = -i
			tail = tail.Next
			continue
		}
		break
	}

	r = mid[0]
	if len(mid) == 1 {
		return mid[0]
	}
	for i := 1; i < len(mid); i++ {
		r = r + mid[i]
	}
	return r
}

func main() {
	fmt.Println(clumsy(10))
}
